package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shaoshaohuo.app.R;

import java.util.List;

/**
 * Created by Administrator on 2017/6/10.
 */

public class SureOderListView extends BaseAdapter {
    private Context context;
    private List<String> data;
    private float total_money;
    private int coupon;
    private int numcoupon;

    public SureOderListView(Context context, List<String> data, float totalmoney, int coupon, int numCoupon) {
        this.context = context;
        this.data = data;
        this.total_money = totalmoney;
        this.coupon = coupon;
        this.numcoupon = numCoupon;
    }

    public void refreshData(int coupon, int numcoupon) {
        this.coupon = coupon;
        this.numcoupon = numcoupon;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public String getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SureOlderAdapterViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.sure_order_listview_item, parent, false);
            holder = new SureOlderAdapterViewHolder();
            holder.sure_order_hint_word = (TextView) convertView.findViewById(R.id.sure_order_hint_word);
            holder.sure_order_jiantou = (ImageView) convertView.findViewById(R.id.sure_order_jiantou);
            holder.sure_order_price = (TextView) convertView.findViewById(R.id.sure_order_price);
            holder.sure_order_word = (TextView) convertView.findViewById(R.id.sure_order_word);
            holder.coupon_tv = (TextView) convertView.findViewById(R.id.coupon_tv);
            convertView.setTag(holder);
        } else {
            holder = (SureOlderAdapterViewHolder) convertView.getTag();
        }
        holder.sure_order_hint_word.setText(data.get(position));
        if (position == 0) {
            holder.sure_order_word.setVisibility(View.VISIBLE);
            holder.sure_order_jiantou.setVisibility(View.VISIBLE);
            holder.sure_order_word.setText("(可用" + numcoupon + "张)");
            holder.sure_order_price.setVisibility(View.GONE);
            if (coupon == 0) {
                holder.coupon_tv.setVisibility(View.GONE);
            } else {
                holder.coupon_tv.setVisibility(View.VISIBLE);
                holder.coupon_tv.setText("-￥ " + coupon);
            }
        } else if (position == 1) {
            holder.sure_order_word.setVisibility(View.VISIBLE);
            holder.sure_order_word.setText(data.get(position));
            holder.sure_order_word.setText("(可用积分0)");
            holder.sure_order_jiantou.setVisibility(View.GONE);
            holder.coupon_tv.setVisibility(View.GONE);
            holder.sure_order_price.setVisibility(View.GONE);
        } else if (position == 2) {
            holder.sure_order_word.setVisibility(View.GONE);
            holder.sure_order_price.setVisibility(View.VISIBLE);
            holder.sure_order_jiantou.setVisibility(View.GONE);
            holder.coupon_tv.setVisibility(View.GONE);
            holder.sure_order_price.setText("￥" + total_money);
        } else if (position == 3) {
            holder.sure_order_word.setVisibility(View.GONE);
            holder.sure_order_price.setVisibility(View.VISIBLE);
            holder.sure_order_price.setText("￥ 0.00");
            holder.coupon_tv.setVisibility(View.GONE);
            holder.sure_order_jiantou.setVisibility(View.GONE);
        }

        return convertView;
    }

    class SureOlderAdapterViewHolder {
        TextView sure_order_hint_word;
        TextView sure_order_word;
        TextView sure_order_price, coupon_tv;
        ImageView sure_order_jiantou;

    }

}
